
function show_stack() {
    Java.perform(function () {
        console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Throwable").$new()));

    })
}


Java.perform(function(){
    console.log("注入成功,请操作触发hook");
    try {
        var Gson =Java.use("com.google.gson.Gson");
        var gson = Gson.$new();
        
    } catch (e) {
        
    }
        function dumpInstance(instance) {
            try {
                var jclazz = instance.getClass();
                var className = jclazz.getName();
                console.log(`\n====== 开始打印实例 ${className}@${instance.hashCode()} 的信息 ======`);
        
                // --- 打印字段 ---
                console.log("  [+] 字段 (Fields):");
                var fields = jclazz.getDeclaredFields();
                if (fields.length === 0) {
                    console.log("无字段");
                } else {
                    fields.forEach(function(field) {
                        try {
                            // 修正：对单个 field 设置 setAccessible
                            field.setAccessible(true);
                            
                            var fieldName = field.getName();
                            var fieldType = field.getType().getName();
                            
                            // 核心修正：从 instance 对象中获取字段值
                            var fieldValue = field.get(instance); 
                            
                            // 对值进行更友好的展示
                            var fieldValueStr =fieldValue;
                            if (fieldValue && typeof fieldValue.toString === 'function') {
                                 try {
                                   //fieldValueStr = fieldValue.toString();
                                   fieldValueStr = gson.A0A(fieldValueStr);
                                 } catch (e) {
                                     // toString 可能会失败，例如对于一些代理类
                                     fieldValueStr = `[无法调用 toString(): ${e.message}]`;
                                 }
                            }
                            console.log(` =======${fieldName}  (${fieldType}): ${fieldValueStr}`);
                        } catch (e) {
                            console.log(`    获取字段 ${field.getName()} 的值失败: ${e.stack}`);
                        }
                    });
                }
        
                // --- 打印方法 ---
                console.log("\n  [+] 方法 (Methods):");
                var methods = jclazz.getDeclaredMethods();
                if (methods.length === 0) {
                    console.log("    无方法");
                } else {
                    methods.forEach(function(method) {
                        var methodName = method.getName();
                        var returnType = method.getReturnType().getName();
                        var parameterTypes = method.getParameterTypes().map(function (p) { return p.getName(); }).join(", ");
                        console.log(`    ${methodName}(${parameterTypes}): ${returnType}`);
                    });
                }
                console.log(`====== 实例 ${className}@${jclazz.hashCode()} 信息打印完毕 ======\n`);
        
            } catch (e) {
                console.log(`dumpInstance 失败：${e}`);
            }
        }
    try {
        // let C48290KTm = Java.use("X.KTm");
        // C48290KTm["invoke"].implementation = function (obj) {
        //     console.log('invoke方法被调用，参数：'+ obj);
        //     console.log("========解析参数======");
        //     dumpInstance(obj);
        //     let ret = this.invoke(obj);
        //     console.log('结果： ' + ret);
        //     //var retClas = ret
        //     console.log("========解析结果======");
        //     dumpInstance(ret);
        //     // console.log("调用堆栈");
        //     // show_stack();
        //     return ret;
        // };
        // let HTTPRequestHandler = Java.use("com.facebook.proxygen.HTTPRequestHandler");
        // HTTPRequestHandler["sendHeadersWithBodyAndEom"].implementation = function (httpUriRequest, bArr, i, i2) {
        //     console.log("================开始打印网络请求=============");
        //     console.log("[+] URL:"+httpUriRequest.getUrl())
        //     console.log('sendHeadersWithBodyAndEom is called' + ', ' + 'httpUriRequest: ' + httpUriRequest + ', ' + 'bArr: ' + bArr + ', ' + 'i: ' + i + ', ' + 'i2: ' + i2);
        //     let ret = this.sendHeadersWithBodyAndEom(httpUriRequest, bArr, i, i2);
        //     console.log('sendHeadersWithBodyAndEom ret value is ' + ret);
        //     return ret;
        // };
        try {
            let C46591sh = Java.use("X.1sh");
            C46591sh["A03"].implementation = function (str) {
                console.log('A03 is called' + ', ' + 'str: ' + str);
                let ret = this.A03(str);
                console.log('A03 ret value is ' + ret);
                return ret;
            };
        } catch (e) {
            console.log("获取函数地址失败："+ e.stack);
        }
        
        // let JniHandler = Java.use("com.facebook.proxygen.JniHandler");
        // JniHandler["sendRequestWithBodyAndEom"].implementation = function (httpUriRequest, bArr, i, i2) {
        //     console.log("================开始打印网络请求=============");
        //     //console.log('sendRequestWithBodyAndEom is called' + ', ' + 'httpUriRequest: ' + httpUriRequest + ', ' + 'bArr: ' + bArr + ', ' + 'i: ' + i + ', ' + 'i2: ' + i2);
        //     // const m = Process.findModuleByName("libmiuiclassproxy.so");
        //     // console.log("so文件地址："+m.base+" 大小："+m.size)
        //     console.log("httpUriRequest类："+httpUriRequest.class)
        //     console.log("[+] URL:"+httpUriRequest.getURI().toString());
        //     console.log('[Method] ', httpUriRequest.getMethod());

            

        //     let ret = this.sendRequestWithBodyAndEom(httpUriRequest, bArr, i, i2);
        //     console.log('sendRequestWithBodyAndEom ret value is ' + ret);
        //     console.log("=============打印调用堆栈=============");
        //     console.log(Java.use("android.util.Log").getStackTraceString(
        //             Java.use("java.lang.Throwable").$new()));
        //     return ret;
        // };


    } catch (e) {
        console.log("注入发生错误："+ e.stack);
    }
    
})